/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mapbox.ohos.gestures.testapp;

import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.BaseDialog;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

import java.lang.ref.WeakReference;

/**
 * HelpDialog
 *
 * @since 2021-07-02
 */
public class HelpDialog extends CommonDialog implements BaseDialog.DialogListener {
    private static WeakReference<Context> weakReference;
    private static HelpDialog helpDialog;

    private HelpDialog(Context context) {
        super(context);
        setDialogListener(this);
    }

    /**
     * newInstance
     *
     * @param context
     * @return HelpDialog
     */
    public static HelpDialog newInstance(Context context) {
        weakReference = new WeakReference<>(context);
        helpDialog = new HelpDialog(context);
        LayoutScatter inflater = LayoutScatter.getInstance(weakReference.get());
        Component helpDialogComponent = inflater.getInstance(weakReference.get()).parse(ResourceTable.Layout_help_dialog, null, false);
        Button gotItButton = (Button) helpDialogComponent.findComponentById(ResourceTable.Id_button_help_got_it);
        gotItButton.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                helpDialog.destroy();
            }
        });
        helpDialog.setContentCustomComponent(helpDialogComponent);
        helpDialog.setTransparent(true);
        return helpDialog;
    }


    @Override
    public boolean isTouchOutside() {
        hide();
        return false;
    }

    @Override
    protected void onShow() {
        super.onShow();
    }
}
